import 'package:xm_app/common/config/Address.dart';
import 'package:xm_app/common/http/api_response.dart';
import 'package:xm_app/common/http/http_utils.dart';
import 'package:xm_app/model/HomeData.dart';
import 'package:xm_app/model/SearchData.dart';
import 'package:xm_app/model/VodDetails.dart';

import 'DaoBase.dart';

class VodDao extends DaoBase {
  static VodDao _instance = VodDao._internal();

  factory VodDao() => _instance;
  VodDao._internal();

  Future<ApiResponse> getHomeList() {
    return vipInvoke(
      () => HttpUtils.get(Address.HOME_API),
      creator: (jsonData) => HomeData.fromJson(jsonData),
    );
  }

  Future<ApiResponse> getVodInfo(int id) {
    return vipInvoke(
      () => HttpUtils.get(Address.HOME_DETAIL_API, params: <String, dynamic>{"id": id}),
      creator: (jsonData) => VodDetails.fromJson(jsonData),
    );
  }

  Future<ApiResponse> search(String keyword, int page) {
    return vipInvoke(
      () => HttpUtils.get(Address.TXT_NORMAL_SEARCH_API, params: <String, dynamic>{"keyword": keyword, "page": page, "cate": "undefined"}),
      creator: (jsonData) => SearchData.fromJson(jsonData),
    );
  }
}
